package com.dream.technology.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.dream.technology.db.entity.RcFlow;
import com.dream.technology.db.entity.RcFlowItem;
import com.dream.technology.db.entity.RcFlowItemQuery;
import com.dream.technology.db.entity.RcFlowQuery;
import com.dream.technology.data.GenericRspDTO;
import com.dream.technology.service.RcFlowItemService;
import com.dream.technology.vo.ErrorCode;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

@Api("风控流程子项")
@RestController
@RequestMapping("/risk/admin/flow_item")
public class RcFlowItemController {

    private static final Logger logger = LoggerFactory.getLogger(RcFlowItemController.class);

    @Autowired
    RcFlowItemService rcFlowItemService;

    /**
     * 风控流程子项接口
     * @param pageNum
     * @param pageSize
     * @param flowCode
     * @param flowName
     * @return
     */
    @GetMapping("/list")
    public GenericRspDTO<Object> getList(Integer pageNum, Integer pageSize, String flowCode, String flowName){

        RcFlowItemQuery rcFlowItemQuery =new RcFlowItemQuery();
        PageHelper.startPage(pageNum,pageSize);
        List<RcFlowItem> rcFlowItemList = rcFlowItemService.selectByExample(rcFlowItemQuery);
        PageInfo pageInfo=new PageInfo(rcFlowItemList);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), pageInfo);
    }

    /**
     * 风控流程子项回显接口
     * @param id
     * @return
     */
    @GetMapping("/id")
    public GenericRspDTO<Object> getById(Long id){

        RcFlowItem rcFlowItem = rcFlowItemService.selectByPrimaryKey(id);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), rcFlowItem);
    }

    /**
     *  添加风控流程子项
     * @param rcFlowItem
     * @return
     */
    @PostMapping("/add")
    public GenericRspDTO<Object> add(RcFlowItem rcFlowItem){

        rcFlowItemService.insert(rcFlowItem);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), null);
    }

    /**
     * 修改风控流程子项
     * @param rcFlowItem
     * @return
     */
    @PostMapping("/update")
    public GenericRspDTO<Object> update(RcFlowItem rcFlowItem){

        rcFlowItemService.updateByPrimaryKey(rcFlowItem);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), null);
    }

    /**
     * 删除风控流程子项 (逻辑删除)
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public GenericRspDTO<Object> delete(Long id){

        rcFlowItemService.deleteByPrimaryKey(id);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), null);
    }
}
